import {
  requestCartgoryOne,
  requestCartgoryThree,
  requestCartgoryTwo,
} from "@/api/product";
import { defineStore } from "pinia";

import type { cartgoryStateType } from "./interface";

export const useCartgoryStore = defineStore("cartgory", {
  state: (): cartgoryStateType => ({
    categoryList1: [],
    categoryList2: [],
    categoryList3: [],
    category1Id: null,
    category2Id: null,
    category3Id: null,
  }),
  actions: {
    // 一级分类请求
    async categoryOneAction() {
      this.categoryList1 = await requestCartgoryOne();
    },
    // 二级分类请求
    async categoryTwoAction() {
      this.categoryList2 = await requestCartgoryTwo(this.category1Id as number);
    },
    // 三级分类请求
    async categoryThreeAction() {
      this.categoryList3 = await requestCartgoryThree(
        this.category2Id as number
      );
    },
  },
});
